package jdbc2;

import com.tedu.InputUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class LoginDemo {
    public static void main(String[] args) {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"欢迎登录","登录");
        try (Connection connection = DBUtil.getConnection()){
            Statement stmt = connection.createStatement();
            /*
            * 用户登录
            * SELECT id,username,password,nickname,age FROM userinfo
            * WHERE username='xxx' AND password='xxx';
            * */
            String sql = "SELECT id,username,password,nickname,age FROM userinfo\n" +
                    "WHERE username='"+ userInfo.getUsername()+"' AND password='"+ userInfo.getPassword()+"';";
            ResultSet rs = stmt.executeQuery(sql);
            if (rs.next()){
                System.out.println("登录成功");
            }else{
                System.out.println("登录失败,用户名或密码不正确");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
